package com.czl.module_storehouse.adapter;

import android.annotation.SuppressLint;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.module_storehouse.databinding.ItemBorrowAddPostBinding;

import java.util.List;

/**
 * @author xubin
 */
public class BorrowAddPostAdapter extends BaseQuickAdapter<SortBean, BaseDataBindingHolder<ItemBorrowAddPostBinding>> {

    public BorrowAddPostAdapter(int layoutResId, @Nullable List<SortBean> data) {
        super(layoutResId, data);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NonNull BaseDataBindingHolder<ItemBorrowAddPostBinding> bindingHolder, SortBean item) {
        ItemBorrowAddPostBinding dataBinding = bindingHolder.getDataBinding();
        if (dataBinding != null) {
            dataBinding.tvApplyNum.setText("数量：" + item.getApplyNum());
            dataBinding.tvAlreadyNum.setText(item.getLendNum() == null ? "0" : String.valueOf(item.getLendNum()));
//            dataBinding.ivRight.setVisibility((item.getBorrowNum() != null && item.getBorrowNum() > 0) ? View.VISIBLE : View.GONE);
            dataBinding.textRemove.setVisibility(View.GONE);
            dataBinding.tvTitle.setText(item.getSortName());
            dataBinding.tvModel.setText("型号：" + item.getSortModel());
            dataBinding.tvNum.setText(String.valueOf(item.getReceiveCount()));
            dataBinding.shadowLayout.setShadowHiddenBottom(bindingHolder.getLayoutPosition() == getData().size() - 1);
            dataBinding.clRoot.setOnClickListener(v -> {
                if (item.getBorrowNum() != null && item.getBorrowNum() == 0) {
                    return;
                }
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(BorrowAddPostAdapter.this, v, bindingHolder.getAbsoluteAdapterPosition());
                }
            });
        }
    }
}
